import { type CrudConfig, type FormFieldConfig } from '@/components';
import urlConstants from '@/constants/urlConstants';
import type { ProColumns } from '@ant-design/pro-components';

// 短信模板数据类型
export interface SmsTemplateRecord {
  paramIndex?: number;
  templateId: string;
  templateName: string;
  contentTemplate: string;
  updateUser?: string;
  updateTime?: string;
  createTime?: string;
}

// 统一的页面配置函数 - 接收 translate 函数作为参数
export const getPageConfig = (translate: (prefix: string, key: string) => string) => {
  const t = (key: string) => translate('dataManage', key);
  const tCommon = (key: string) => translate('common', key);

  return {
    // CRUD配置
    crudConfig: {
      endpoints: {
        list: urlConstants.ADUIT_MANAGE.LIST,
        create: urlConstants.ADUIT_MANAGE.CREATE,
        update: urlConstants.ADUIT_MANAGE.EDIT,
        delete: urlConstants.ADUIT_MANAGE.DELETE,
        detail: urlConstants.ADUIT_MANAGE.LIST,
      },
    } as CrudConfig,

    // 搜索字段配置
    searchFields: [
      {
        name: 'templateId',
        label: t('templateId'),
        type: 'input' as const,
      },
      {
        name: 'templateName',
        label: t('templateName'),
        type: 'input' as const,
      },
    ],

    // 表格列配置
    columns: [
      {
        title: tCommon('paramIndex'),
        dataIndex: 'paramIndex',
        key: 'paramIndex',
        width: 80,
        fixed: 'left',
      },
      {
        title: t('templateId'),
        dataIndex: 'templateId',
        key: 'templateId',
        width: 120,
        copyable: true,
      },
      {
        title: t('templateName'),
        dataIndex: 'templateName',
        key: 'templateName',
        width: 180,
        ellipsis: true,
      },
      {
        title: t('contentTemplate'),
        dataIndex: 'contentTemplate',
        key: 'contentTemplate',
        width: 300,
        ellipsis: true,
      },
      {
        title: tCommon('updateUser'),
        dataIndex: 'updateUser',
        key: 'updateUser',
        width: 120,
      },
      {
        title: tCommon('updateTime'),
        dataIndex: 'updateTime',
        key: 'updateTime',
        width: 160,
        valueType: 'dateTime',
      },
    ] as ProColumns<SmsTemplateRecord>[],

    // 表单字段配置
    formFields: [
      {
        name: 'templateId',
        label: t('templateId'),
        type: 'select' as const,
        options: [], // 这里应该从字典获取数据
        rules: [{ required: true, message: t('templateIdRequired') }],
      },
      {
        name: 'templateName',
        label: t('templateName'),
        type: 'input' as const,
        rules: [{ required: true, message: t('templateNameRequired') }],
      },
      {
        name: 'contentTemplate',
        label: t('contentTemplate'),
        type: 'textarea' as const,
        rules: [{ required: true, message: t('contentTemplateRequired') }],
        span: 24,
      },
    ] as FormFieldConfig[],

    // 字典枚举配置
    dictEnum: {},
  };
};
